﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Caculator2._0
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Caculate_Click(object sender, EventArgs e)
        {
            try
            {
                double result = 0;
                double Num1 = Convert.ToInt32(TextBox_Num1.Text);
                double Num2 = Convert.ToInt32(TextBox_Num2.Text);
                
                switch (comboBox_Math.Text)
                {
                    case "+":
                        result = Num1 + Num2;
                        break;
                    case "-":
                        result = Num1 - Num2;
                        break;
                    case "*":
                        result = Num1 * Num2;
                        break;
                    case "/":
                        if(Num2==0)
                        {
                            Console.WriteLine("请输入一个不为零的整数作为被除数！");
                            Num2 = Convert.ToInt32(TextBox_Num2);
                            return;
                        }
                        else
                        {
                            result = Num1 / Num2;

                        }
                        break;
                    default:
                        Result.Text = "请选择一个运算符";
                        break;
                }
                Result.Text = result.ToString();
            }
            catch(FormatException)
            {
                Result.Text = "输入格式错误！";

            }
            catch(OverflowException)
            {
                Result.Text = "发生了溢出！";
            }
        }
        
    }
}
